﻿using BLL;
using Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PropertyAppraisal
{
    public partial class Registered : System.Web.UI.Page
    {
        //部门bll实例化
        private static DepartmentBll bll = new DepartmentBll();
        //人员bll实例化
        private static UsersBll userbll = new UsersBll();
        //登记基本信息表bll实例化
        private static Basic_InfoBll Basicbll = new Basic_InfoBll();
        //借款人信息表bll实例化
        private static Loan_InfoBll Loanbll = new Loan_InfoBll();


        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 绑定部门下拉框
        /// </summary>
        /// <returns></returns>
        public static string departmentBD()
        {
            List<SysDepartment> dept = bll.DepartmentBD();
            var HtmlStr = "";
            for (var i = 0; i < dept.Count; i++)
            {
                HtmlStr += "<option value=\"" + dept[i].department_Id + "\">" + dept[i].department_Name + "</option>";
            }
            return HtmlStr;
        }


        /// <summary>
        /// 绑定勘察员估价员下拉框
        /// </summary>
        /// <returns></returns>
        [WebMethod]
        public static string KCSelectBD(int newValue, int role)
        {
            if (role == 2)
            {
                List<SysUser> dept = userbll.GetUsers(newValue, role);
                return JsonConvert.SerializeObject(dept);
            }
            else
            {
                if (role == 3)
                {
                    List<SysUser> User = userbll.GetUsers(newValue, role);
                    return JsonConvert.SerializeObject(User);
                }
                else
                {
                    return "";
                }
            }
        }


        /// <summary>
        /// 绑定房屋用途下拉框
        /// </summary>
        /// <returns></returns>
        public static string DictionaryBD()
        {
            DictionaryBll Dictionarybll = new DictionaryBll();
            List<SysDictionary> Dictionary = Dictionarybll.sb(1);
            var HtmlStr = "";
            for (var i = 0; i < Dictionary.Count; i++)
            {
                HtmlStr += "<option value=\"" + Dictionary[i].Dictionary_Number + "\">" + Dictionary[i].dictionary_Name + "</option>";
            }
            return HtmlStr;
        }

        /// <summary>
        /// 绑定建成年代来源下拉框
        /// </summary>
        /// <returns></returns>
        public static string YersBD()
        {
            DictionaryBll Dictionarybll = new DictionaryBll();
            List<SysDictionary> Dictionary = Dictionarybll.sb(2);
            var HtmlStr = "";
            for (var i = 0; i < Dictionary.Count; i++)
            {
                HtmlStr += "<option value=\"" + Dictionary[i].Dictionary_Number + "\">" + Dictionary[i].dictionary_Name + "</option>";
            }
            return HtmlStr;
        }

        /// <summary>
        /// 绑定报告类型下拉框
        /// </summary>
        /// <returns></returns>
        public static string BGTypeBD()
        {
            DictionaryBll Dictionarybll = new DictionaryBll();
            List<SysDictionary> Dictionary = Dictionarybll.sb(3);
            var HtmlStr = "";
            for (var i = 0; i < Dictionary.Count; i++)
            {
                HtmlStr += "<option value=\"" + Dictionary[i].Dictionary_Number + "\">" + Dictionary[i].dictionary_Name + "</option>";
            }
            return HtmlStr;
        }


        /// <summary>
        /// 登记
        /// </summary>
        [WebMethod]
        public static bool AddBasicInfo(string loan_Name, string loan_IdCard, string loan_TEL, string loan_Contacts, string loan_ContactsTEL, int surplus_Years, decimal basic_Quota, string house_Located, int house_Purpose, int yers_Source, string house_Time, int presentation_Type, int the_Department, int survey, int evaluation, DateTime issue_Time, string assessment)
        {
           // 添加房屋基本信息
            EABasic_Info bif = new EABasic_Info();
            bif.surplus_Years = surplus_Years;
            bif.basic_Quota = basic_Quota;
            bif.house_Located = house_Located;
            bif.house_Purpose = house_Purpose;
            bif.house_Time = house_Time;
            bif.yers_Source = yers_Source;
            bif.assessment = assessment;
            bif.presentation_Type = presentation_Type;
            bif.the_Department = the_Department;
            bif.survey = survey;
            bif.evaluation = evaluation;
            bif.basic_State = 0;
            bif.basic_CreateTime = DateTime.Now;
            bif.user_Id = 1;
            bif.issue_Time = Convert.ToDateTime(issue_Time);
            bif.survey_StartTime = DateTime.Now;
            bif.survey_EndTime = DateTime.Now;
            bif.basic_ValueTime = DateTime.Now;

            if (Basicbll.BasicAdd(bif))
            {
                string number = Basicbll.GetBasic();
                if (number != null)
                {
                    //添加贷款人
                    EALoan_Info li = new EALoan_Info();
                    li.loan_Name = loan_Name;
                    li.loan_IdCard = loan_IdCard;
                    li.loan_TEL = loan_TEL;
                    li.loan_ContactsTEL = loan_ContactsTEL;
                    li.loan_Contacts = loan_Contacts;
                    li.createTime = DateTime.Now;
                    li.create_People = "admin";
                    li.projectNumber = number.ToString();

                    if (Loanbll.LoanAdd(li))
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            return false;

        }
    }
}